#include <stdio.h>
#include <string.h>
#include <stdlib.h>

	struct segtype {
		int l, r;
	} seg[100010];
	int n;
	int M;
	int count = 0;
	int ans[100010];

int my_compr(const void * arg1, const void * arg2)
{
	struct segtype * p1, * p2;
	p1 = (struct segtype *) arg1;
	p2 = (struct segtype *) arg2;
	return ((p1->l) - (p2->l));
}

main()
{
	int left, right;
	int i, j, k;
	int end, farthest;

	scanf("%ld", &M);
	while (scanf("%ld%ld", &left, &right), left || right)
	{
		n++;
		seg[n].l = left;
		seg[n].r = right;
	}
	qsort(seg+1,n,sizeof(struct segtype),my_compr);

	end = 0;
	i = 1;
	farthest = 0;
	while (i <= n && seg[i].l <= end)
	{
		count++;
		while (i <= n && seg[i].l <= end)
		{
			if (seg[i].r > farthest)
			{
				farthest = seg[i].r;
				ans[count] = i;
			}
			i++;
		}
		if (i > n) break;
		if (farthest >= M) break;
		end = farthest;
	}

	if (farthest < M) printf("No solution\n");
	else 
	{
		printf("%ld\n", count);
		for (i=1; i<=count; i++)
			printf("%ld %ld\n", seg[ans[i]].l ,seg[ans[i]].r);
	}
	return 0;
}
